package com.icehand.payment.config;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.google.common.collect.Lists;
import com.icehand.mybatis.payment.mapper.PayNotifyRecordMapper;
import com.icehand.payment.pay.Pay;
import com.icehand.payment.pay.PayTemplate;
import com.icehand.payment.pay.alipay.AliAppPay;
import com.icehand.payment.pay.alipay.AliPcPay;
import com.icehand.payment.pay.alipay.AliWapPay;
import com.icehand.payment.pay.wechat.app.WechatAppPay;
import com.icehand.payment.pay.wechat.js.WechatJsPay;
import com.icehand.payment.pay.wechat.mini.WechatMiniPay;
import com.icehand.wechat.js.WechatJsHelper;
import com.icehand.wechat.mini.WechatMiniHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author icehand
 */
@Configuration
public class PayConfiguration {
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public XmlMapper xmlMapper(){
        return new XmlMapper();
    }

    @Bean
    public PayTemplate payTemplate(RestTemplate restTemplate, XmlMapper xmlMapper, WechatJsHelper wechatJsHelper,
                                   WechatMiniHelper wechatMiniHelper, PayNotifyRecordMapper payNotifyRecordMapper){
        List<Pay> list = Lists.newArrayList();
        list.add(new WechatAppPay(restTemplate,xmlMapper,payNotifyRecordMapper));
        list.add(new WechatJsPay(restTemplate, xmlMapper, wechatJsHelper,payNotifyRecordMapper));
        list.add(new WechatMiniPay(restTemplate, xmlMapper, wechatMiniHelper,payNotifyRecordMapper));
        list.add(new AliAppPay(restTemplate,payNotifyRecordMapper));
        list.add(new AliWapPay(restTemplate,payNotifyRecordMapper));
        list.add(new AliPcPay(restTemplate,payNotifyRecordMapper));
        return new PayTemplate(list);
    }
}
